package tools;

import java.security.*;
/**
 *
 * @author HP
 */
public class Encryptor {
    
     public static String encrypt(String encryptThis) {

        String sessionid = encryptThis;

        byte[] defaultBytes = sessionid.getBytes();
        try {
            MessageDigest algorithm = MessageDigest.getInstance("MD5");
            algorithm.reset();
            algorithm.update(defaultBytes);
            byte messageDigest[] = algorithm.digest();

            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < messageDigest.length; i++) {
                hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
            }

            //System.out.println("sessionid: " + sessionid + " \nmd5 version is: " + hexString.toString());
            sessionid = hexString + "";

        } catch (NoSuchAlgorithmException nsae) {
            //Left blank intentionally
        }
        return sessionid;
    }
}
